<?php
/**
 * Created by PhpStorm.
 * Author: kaodou
 * Date: 2017/10/18
 * Time: 14:30
 */
namespace App\Eloquent\Ygt;

use Framework\BaseClass\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductFields extends DbEloquent
{
    use SoftDeletes;
    protected $dates = ['deleted_at'];

    protected $table = 'ygt_product_fields';

    public static function getTransformListToArr($where,$type=1,$limit='',$offset='',$orderby=['id','asc'],$isHideCompute=0)
    {
        $productFieldsList  = ProductFields::getList($where,'',$limit,$offset,$orderby)->toArray();
        $result             = [];
        switch ($type)
        {
            case 1:
                foreach($productFieldsList as $key=>$val)
                {
                    $productId      = $val['assemblage_material_id'];
                    $fieldType      = $val['field_type'];
                    $unit           = $val['unit'];
                    $fieldValue     = $fieldType==1 ? $val['varchar'] : $val['numerical'];

//                    //如果是计量属性且值为0 不显示
//                    if($isHideCompute){
//                        if(isset($val['is_compute']) && $val['is_compute'] && !$fieldValue){
//                            continue;
//                        }
//                    }

                    $temp           = [
                        'id'=>$val['id'],
                        'field_name'=>$val['field_name'],
                        'field_value'=>$fieldValue.$unit,
                        'is_compute'=>$val['is_compute'],
                        'unit'=>$val['unit'],
                    ];
                    $result[$productId][]   = $temp;
                }
                break;
            case 2:
                break;
            default:
        }
        return $result;
    }

}
